//
//  BottomBarView.swift
//  MyCloset
//
//  Created by 牟好好 on 2024/11/6.
//

import SwiftUI

struct BottomBarView: View {
    @Binding var selectedTab: String
    
    var body: some View {
        Group {
            HStack {
                ForEach(tabs, id: \.self) { tab in
                    Button {
                        withAnimation(.spring(duration: 0.1)) {
                            selectedTab = tab
                        }
                    } label: {
                        Image(systemName: selectedTab == tab ? tab + ".fill" : tab)
                            .font(.system(size: boundsHeight * 0.035))
                            .foregroundStyle(selectedTab == tab ? getColor(tab: tab) : .gray)
                            .scaleEffect(selectedTab == tab ? 1.1 : 0.9)
                    }
                    
                    if tab != tabs.last {
                        Spacer()
                    }
                }
            }
            .padding(boundsWidth * 0.07)
            .frame(height: boundsHeight * 0.08)
            .background(.white)
            .clipShape(RoundedRectangle(cornerRadius: 25))
            .shadow(radius: 8)
        }
        .padding()
    }
    
    func getColor(tab: String) -> Color {
        switch tab {
        case "house":
            return .red
        case "camera":
            return .yellow
        case "gearshape":
            return .blue
        default:
            return .clear
        }
    }
}

#Preview {
    BottomBarView(selectedTab: .constant("house"))
}
